$(function(){
	var begin = "<xml>\r\n";
	var toUserName = "<ToUserName><![CDATA["+$("#ToUserName").val()+"]]></ToUserName>\r\n";
	var AgentID = "<AgentID>"+$("#AgentID").val()+"</AgentID>\r\n";
	var fromUserName = "<FromUserName><![CDATA["+$("#FromUserName").val()+"]]></FromUserName>\r\n";
	var content = "<Content><![CDATA["+$("#nr").val()+"]]></Content>\r\n";
	var msgId = "<MsgId>1234567890123456</MsgId>\r\n";
	var mediaId = "<MediaId><![CDATA[1234567890]]></MediaId>\r\n";
	var format = "<Format><![CDATA["+$("#yy").val()+"]]></Format>\r\n";
	var picUrl = "<PicUrl><![CDATA["+$("#tp").val()+"]]></PicUrl>\r\n";
	var location_X = "<Location_X>"+$("#x").val()+"</Location_X>\r\n";
	var location_Y = "<Location_Y>"+$("#y").val()+"</Location_Y>\r\n";
	var scale = "<Scale>20</Scale>\r\n";
	var label = "<Label><![CDATA[位置信息]]></Label>\r\n";
	var ThumbMediaId = "<ThumbMediaId><![CDATA[1234567890]]></ThumbMediaId>\r\n";
	var LLP = "<Latitude>23.104105</Latitude>\r\n"+
	"<Longitude>113.320107</Longitude>\r\n"+
	"<Precision>65.000000</Precision>\r\n";
	var EventKey = "<EventKey><![CDATA[]]></EventKey>\r\n";
	var tzEventKey = "<EventKey><![CDATA[www.qq.com]]></EventKey>\r\n";
	var sm1EventKey = "<EventKey><![CDATA[]]></EventKey>\r\n";
	var sm2EventKey = "<EventKey><![CDATA[]]></EventKey>\r\n";
	var ScanCodeInfo = "<ScanCodeInfo>\r\n"+
	"<ScanType><![CDATA[qrcode]]></ScanType>\r\n"+
	"<ScanResult><![CDATA[]]></ScanResult>\r\n"+
	"</ScanCodeInfo>\r\n";
	var ScanCodeInfo2 = "<ScanCodeInfo>\r\n"+
	"<ScanType><![CDATA[qrcode]]></ScanType>\r\n"+
	"<ScanResult><![CDATA[]]></ScanResult>\r\n"+
	"</ScanCodeInfo>\r\n";
	var tc1EventKey = "<EventKey><![CDATA[]]></EventKey>\r\n";
	var tc1SendPicsInfo = "<SendPicsInfo>\r\n"+
	"<Count></Count>\r\n"+
	"<PicList>\r\n"+
	"<item>\r\n"+
	"<PicMd5Sum><![CDATA[1b5f7c23b5bf75682a53e7b6d163e185]]></PicMd5Sum>\r\n"+
	"</item>\r\n"+
	"</PicList>\r\n"+
	"</SendPicsInfo>\r\n";
	var tc2EventKey = "<EventKey><![CDATA[]]></EventKey>\r\n";
	var tc2SendPicsInfo = "<SendPicsInfo>\r\n"+
	"<Count></Count>\r\n"+
	"<PicList>\r\n"+
	"<item>\r\n"+
	"<PicMd5Sum><![CDATA[1b5f7c23b5bf75682a53e7b6d163e185]]></PicMd5Sum>\r\n"+
	"</item>\r\n"+
	"</PicList>\r\n"+
	"</SendPicsInfo>\r\n";
	var tc3EventKey = "<EventKey><![CDATA[]]></EventKey>\r\n";
	var tc3SendPicsInfo = "<SendPicsInfo>\r\n"+
	"<Count></Count>\r\n"+
	"<PicList>\r\n"+
	"<item>\r\n"+
	"<PicMd5Sum><![CDATA[1b5f7c23b5bf75682a53e7b6d163e185]]></PicMd5Sum>\r\n"+
	"</item>\r\n"+
	"</PicList>\r\n"+
	"</SendPicsInfo>\r\n";
	var tc4EventKey = "<EventKey><![CDATA[]]></EventKey>\r\n";
	var SendLocationInfo = "<SendLocationInfo>\r\n"+
	"<Location_X><![CDATA[]]></Location_X>\r\n"+
	"<Location_Y><![CDATA[]]></Location_Y>\r\n"+
	"<Scale><![CDATA[]]></Scale>\r\n"+
	"<Label><![CDATA[广州市海珠区客村艺苑路 106号]]></Label>\r\n"+
	"<Poiname><![CDATA[]]></Poiname>\r\n"+
	"</SendLocationInfo>\r\n";
	var fromsysName = "<FromUserName><![CDATA[sys]]></FromUserName>\r\n";
	var BatchJob1 = "<BatchJob><JobId><![CDATA[S0MrnndvRG5fadSlLwiBqiDDbM143UqTmKP3152FZk4]]></JobId>\r\n";
	var jobtype = "<JobType><![CDATA[sync_user]]></JobType>\r\n";
	var BatchJob2 = "<ErrCode>0</ErrCode>\r\n"+
	"<ErrMsg><![CDATA[ok]]></ErrMsg>\r\n"+
	"</BatchJob>\r\n";
	var end = "</xml>";
	var time = parseInt(new Date().getTime()/1000);
	var br = "\r\n-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\r\n"
	function msgType(type){
		return "<MsgType><![CDATA["+type+"]]></MsgType>\r\n";
	}
	function event(event){
		return "<Event><![CDATA["+event+"]]></Event>\r\n";
	}
	
	//类型选择
	$('input[type="radio"]').click(function(){
		time = parseInt(new Date().getTime()/1000);
		var createTime = "<CreateTime>"+time+"</CreateTime>\r\n";
		if($(this).val()==0){//文本
			$("#content").val(begin+toUserName+fromUserName+createTime+msgType("text")+content+msgId+AgentID+end);
			$(".nytz").children().addClass("hidden");
			$(".nr").removeClass("hidden");
		}else if($(this).val()==1){//语音
			$("#content").val(begin+toUserName+fromUserName+createTime+msgType("voice")+mediaId+format+msgId+AgentID+end);
			$(".nytz").children().addClass("hidden");
			$(".yy").removeClass("hidden");
		}else if($(this).val()==2){//图片
			$("#content").val(begin+toUserName+fromUserName+createTime+msgType("image")+picUrl+mediaId+msgId+AgentID+end);
			$(".nytz").children().addClass("hidden");
			$(".tp").removeClass("hidden");
		}else if($(this).val()==3){//位置
			$("#content").val(begin+toUserName+fromUserName+createTime+msgType("location")+location_X+location_Y+scale+label+msgId+AgentID+end);
			$(".nytz").children().addClass("hidden");
			$(".wz").removeClass("hidden");
		}else if($(this).val()==4){//关注
			$("#content").val(begin+toUserName+fromUserName+createTime+msgType("event")+event("subscribe")+AgentID+end);
			$(".nytz").children().addClass("hidden");
		}else if($(this).val()==5){//取消关注
			$("#content").val(begin+toUserName+fromUserName+createTime+msgType("event")+event("unsubscribe")+AgentID+end);
			$(".nytz").children().addClass("hidden");
		}else if($(this).val()==6){//视频
			$("#content").val(begin+toUserName+fromUserName+createTime+msgType("video")+mediaId+ThumbMediaId+msgId+AgentID+end);
			$(".nytz").children().addClass("hidden");
		}else if($(this).val()==7){//小视频
			$("#content").val(begin+toUserName+fromUserName+createTime+msgType("shortvideo")+mediaId+ThumbMediaId+msgId+AgentID+end);
			$(".nytz").children().addClass("hidden");
		}else if($(this).val()==8){//上报地理位置
			$("#content").val(begin+toUserName+fromUserName+createTime+msgType("event")+event("LOCATION")+LLP+AgentID+end);
			$(".nytz").children().addClass("hidden");
			$(".sbwz").removeClass("hidden");
		}else if($(this).val()==9){//点击菜单拉取消息
			$("#content").val(begin+toUserName+fromUserName+createTime+msgType("event")+event("CLICK")+EventKey+AgentID+end);
			$(".nytz").children().addClass("hidden");
			$(".menukey").removeClass("hidden");
		}else if($(this).val()==10){//点击菜单跳转链接
			$("#content").val(begin+toUserName+fromUserName+createTime+msgType("event")+event("VIEW")+tzEventKey+AgentID+end);
			$(".nytz").children().addClass("hidden");
			$(".tzmenukey").removeClass("hidden");
		}else if($(this).val()==11){//扫码事件1
			$("#content").val(begin+toUserName+fromUserName+createTime+msgType("event")+event("scancode_push")+sm1EventKey+ScanCodeInfo+AgentID+end);
			$(".nytz").children().addClass("hidden");
			$(".saoma1key").removeClass("hidden");
			$(".saoma1result").removeClass("hidden");
		}else if($(this).val()==12){//扫码事件2
			$("#content").val(begin+toUserName+fromUserName+createTime+msgType("event")+event("scancode_waitmsg")+sm2EventKey+ScanCodeInfo2+AgentID+end);
			$(".nytz").children().addClass("hidden");
			$(".saoma2key").removeClass("hidden");
			$(".saoma2result").removeClass("hidden");
		}else if($(this).val()==13){//弹出事件 拍照发图
			$("#content").val(begin+toUserName+fromUserName+createTime+msgType("event")+event("pic_sysphoto")+tc1EventKey+tc1SendPicsInfo+AgentID+end);
			$(".nytz").children().addClass("hidden");
			$(".tc1key").removeClass("hidden");
			$(".tc1count").removeClass("hidden");
		}else if($(this).val()==14){//弹出事件 拍照或相册
			$("#content").val(begin+toUserName+fromUserName+createTime+msgType("event")+event("pic_photo_or_album")+tc2EventKey+tc2SendPicsInfo+AgentID+end);
			$(".nytz").children().addClass("hidden");
			$(".tc2key").removeClass("hidden");
			$(".tc2count").removeClass("hidden");
		}else if($(this).val()==15){//弹出事件 微信相册
			$("#content").val(begin+toUserName+fromUserName+createTime+msgType("event")+event("pic_weixin")+tc3EventKey+tc3SendPicsInfo+AgentID+end);
			$(".nytz").children().addClass("hidden");
			$(".tc3key").removeClass("hidden");
			$(".tc3count").removeClass("hidden");
		}else if($(this).val()==16){//弹出事件 地理位置
			$("#content").val(begin+toUserName+fromUserName+createTime+msgType("event")+event("location_select")+tc4EventKey+SendLocationInfo+AgentID+end);
			$(".nytz").children().addClass("hidden");
			$(".tc4key").removeClass("hidden");
			$(".zuobiaox").removeClass("hidden");
			$(".zuobiaoy").removeClass("hidden");
			$(".jingdu").removeClass("hidden");
		}else if($(this).val()==17){//成员进入应用
			$("#content").val(begin+toUserName+fromUserName+createTime+msgType("event")+event("enter_agent")+EventKey+AgentID+end);
			$(".nytz").children().addClass("hidden");
		}else if($(this).val()==18){//异步任务完成
			$("#content").val(begin+toUserName+fromsysName+createTime+msgType("event")+event("batch_job_result")+BatchJob1+jobtype+BatchJob2+AgentID+end);
			$(".nytz").children().addClass("hidden");
			$(".job_type").removeClass("hidden");
		}
	});
	
	//页面打开默认选中文本
	$("#wenben").click();
	
	//将文本框中的内容同步到参数文本域中
	$("#ToUserName,#FromUserName,#nr,#yy,#tp,#x,#y,#AgentID,#sbx,#sby,#sbj,#menukey,#tzmenukey,#saoma1key,#saoma1result,#saoma2key,#saoma2result,#tc1key,#tc1count,#tc2key,#tc2count,"+
	"#tc3key,#tc3count,#tc4key,#zuobiaox,#zuobiaoy,#jingdu,#sj1,#sj2,#job_type").bind("keyup keydown propertychange input change",function(time){
		fromUserName = "<FromUserName><![CDATA["+$("#FromUserName").val()+"]]></FromUserName>\r\n";
		toUserName = "<ToUserName><![CDATA["+$("#ToUserName").val()+"]]></ToUserName>\r\n";
		content = "<Content><![CDATA["+$("#nr").val()+"]]></Content>\r\n";
		format = "<Format><![CDATA["+$("#yy").val()+"]]></Format>\r\n";
		picUrl = "<PicUrl><![CDATA["+$("#tp").val()+"]]></PicUrl>\r\n";
		location_X = "<Location_X>"+$("#x").val()+"</Location_X>\r\n";
		location_Y = "<Location_Y>"+$("#y").val()+"</Location_Y>\r\n";
		AgentID = "<AgentID>"+$("#AgentID").val()+"</AgentID>\r\n";
		LLP = "<Latitude>"+$("#sbx").val()+"</Latitude>\r\n<Longitude>"+$("#sby").val()+"</Longitude>\r\n<Precision>"+$("#sbj").val()+"</Precision>\r\n";
		EventKey = "<EventKey><![CDATA["+$("#menukey").val()+"]]></EventKey>\r\n";
		tzEventKey = "<EventKey><![CDATA["+$("#tzmenukey").val()+"]]></EventKey>\r\n";
		sm1EventKey = "<EventKey><![CDATA["+$("#saoma1key").val()+"]]></EventKey>\r\n";
		ScanCodeInfo = "<ScanCodeInfo>\r\n"+
		"<ScanType><![CDATA[qrcode]]></ScanType>\r\n"+
		"<ScanResult><![CDATA["+$("#saoma1result").val()+"]]></ScanResult>\r\n"+
		"</ScanCodeInfo>\r\n";
		sm2EventKey = "<EventKey><![CDATA["+$("#saoma2key").val()+"]]></EventKey>\r\n";
		ScanCodeInfo2 = "<ScanCodeInfo>\r\n"+
		"<ScanType><![CDATA[qrcode]]></ScanType>\r\n"+
		"<ScanResult><![CDATA["+$("#saoma2result").val()+"]]></ScanResult>\r\n"+
		"</ScanCodeInfo>\r\n";
		tc1EventKey = "<EventKey><![CDATA["+$("#tc1key").val()+"]]></EventKey>\r\n";
		var tmpstr="";
		for(var i=0;i<($("#tc1count").val())*1;i++){
			tmpstr=tmpstr+"<item>\r\n"+
		"<PicMd5Sum><![CDATA[1b5f7c23b5bf75682a53e7b6d163e185]]></PicMd5Sum>\r\n"+
		"</item>\r\n";
		}
		tc1SendPicsInfo = "<SendPicsInfo>\r\n"+
		"<Count>"+$("#tc1count").val()+"</Count>\r\n"+
		"<PicList>\r\n"+tmpstr+
		"</PicList>\r\n"+
		"</SendPicsInfo>\r\n";
		tc2EventKey = "<EventKey><![CDATA["+$("#tc2key").val()+"]]></EventKey>\r\n";
		tmpstr="";
		for(var i=0;i<($("#tc2count").val())*1;i++){
			tmpstr=tmpstr+"<item>\r\n"+
		"<PicMd5Sum><![CDATA[1b5f7c23b5bf75682a53e7b6d163e185]]></PicMd5Sum>\r\n"+
		"</item>\r\n";
		}
		tc2SendPicsInfo = "<SendPicsInfo>\r\n"+
		"<Count>"+$("#tc2count").val()+"</Count>\r\n"+
		"<PicList>\r\n"+tmpstr+
		"</PicList>\r\n"+
		"</SendPicsInfo>\r\n";
		tc3EventKey = "<EventKey><![CDATA["+$("#tc3key").val()+"]]></EventKey>\r\n";
		tmpstr="";
		for(var i=0;i<($("#tc3count").val())*1;i++){
			tmpstr=tmpstr+"<item>\r\n"+
		"<PicMd5Sum><![CDATA[1b5f7c23b5bf75682a53e7b6d163e185]]></PicMd5Sum>\r\n"+
		"</item>\r\n";
		}
		tc3SendPicsInfo = "<SendPicsInfo>\r\n"+
		"<Count>"+$("#tc3count").val()+"</Count>\r\n"+
		"<PicList>\r\n"+tmpstr+
		"</PicList>\r\n"+
		"</SendPicsInfo>\r\n";
		tc4EventKey = "<EventKey><![CDATA["+$("#tc4key").val()+"]]></EventKey>\r\n";
		SendLocationInfo = "<SendLocationInfo>\r\n"+
		"<Location_X><![CDATA["+$("#zuobiaox").val()+"]]></Location_X>\r\n"+
		"<Location_Y><![CDATA["+$("#zuobiaoy").val()+"]]></Location_Y>\r\n"+
		"<Scale><![CDATA["+$("#jingdu").val()+"]]></Scale>\r\n"+
		"<Label><![CDATA[广州市海珠区客村艺苑路 106号]]></Label>\r\n"+
		"<Poiname><![CDATA[]]></Poiname>\r\n"+
		"</SendLocationInfo>\r\n";
		jobtype = "<JobType><![CDATA["+$("#job_type").val()+"]]></JobType>\r\n";
		$('input[type="radio"]:checked').click();
	});
	
	//清空结果文本域
	$("#clear").click(function(){
		$("#content_back").val("");
	});
	
	//点击提交按钮
	$("#button").click(function(){
		var aes = $("#EncodingAESKey").val();
		var corpId = $("#ToUserName").val();
		var url = $("#URL").val();
		var con = $("#content_back").val();
		var data123 = $("#content").val();
		$.post("demo3.php",{aes:aes,corpId:corpId,data:data123,url:url,token:$("#token").val()},function(rs){
			if(con==""){
				$("#content_back").val(rs);
			}else{
				$("#content_back").val(con+br+rs);
			}
		});
	});
	
	$(".default").click(function(){
		if($(this).parent().parent().hasClass("chosen-with-drop")){
			$(".chosen-container").removeClass("chosen-with-drop");
		}else{//显示	
			$(".chosen-container").removeClass("chosen-with-drop");
			$(this).parent().parent().addClass("chosen-with-drop");
		}
	});
});